new Swiper(".banner-swiper", {
  autoplay: {
    disableOnInteraction: false,
  },
  pagination: {
    el: ".banner-pagination",
    clickable: true,
  },
});
new Swiper(".news-col-left", {
  autoplay: {
    disableOnInteraction: false,
    delay: 3000,
  },
  mousewheel: true,
  pagination: {
    el: ".news-pagination",
    clickable: true,
  },
});
new Swiper(".part-swiper", {
  navigation: {
    nextEl: ".part-next",
    prevEl: ".part-prev",
  },
});
/* new Swiper('.donn-swiper', {
  autoplay: {
    disableOnInteraction: false,
    delay: 3000
  },
  pagination: {
    el: '.swiper-pagination',
    clickable: true
  },
  on: {
    init: function () {
      swiperAnimateCache(this); //隐藏动画元素
      swiperAnimate(this); //初始化完成开始动画
    },
    slideChangeTransitionEnd: function () {
      swiperAnimate(this); //每个slide切换结束时也运行当前slide动画
      //this.slides.eq(this.activeIndex).find('.ani').removeClass('ani'); 动画只展现一次，去除ani类名
    },
    slideChangeTransitionEnd: function () {//切换完执行的方法
      numPage = this.activeIndex; //当前是第几个页面
      for (var i = 0; i < donnLeft.length; i++) {
        donnLeft[i].classList.remove('active')
      }
      donnLeft[numPage].classList.add('active')
    }
  }
}); */
// 网络参与尽责
function $$(elem) {
  return document.querySelectorAll(elem);
}
var i = 0,
  setRun = null;
function run(bol) {
  for (var j = 0; j < $$(".donn-swiper img").length; j++) {
    $$(".donn-swiper img")[j].style.zIndex = 0;
    if (i >= $$(".donn-swiper img").length - 1) {
      $$(".donn-swiper img")[0].style.zIndex = 1;
    } else {
      $$(".donn-swiper img")[i + 1].style.zIndex = 1;
    }
  }
  if (bol) {
    imgActive();
  }
  setRun = setInterval(function () {
    imgZIndex();
    imgActive();
  }, 5000);
}
run();
// 判断层级
function imgZIndex() {
  for (var j = 0; j < $$(".donn-swiper img").length; j++) {
    $$(".donn-swiper img")[j].style.zIndex = 0;
    if (i >= $$(".donn-swiper img").length - 1) {
      $$(".donn-swiper img")[0].style.zIndex = 1;
    } else {
      $$(".donn-swiper img")[i + 1].style.zIndex = 1;
    }
  }
}
// 判断展示
function imgActive() {
  for (var j = 0; j < $$(".donn-swiper img").length; j++) {
    $$(".donn-swiper img")[j].classList.remove("active");
    $$(".donn-pagination span")[j].classList.remove("active");
    $$(".donn-main .donn-left")[j].classList.remove("active");
  }
  $$(".donn-swiper img")[i].classList.add("active");
  $$(".donn-pagination span")[i].classList.add("active");
  $$(".donn-main .donn-left")[i].classList.add("active");
  i++;
  if (i >= $$(".donn-swiper img").length) {
    i = 0;
  }
}
function clickBtn(num) {
  clearInterval(setRun);
  i = num;
  run(1);
}

new Swiper(".cert-swiper", {
  navigation: {
    nextEl: ".cert-next",
    prevEl: ".cert-prev",
  },
});
$(".cert-nav>div").each(function (i) {
  $(this).click(function () {
    $(".cert-nav>div").removeClass("active");
    $(this).addClass("active");
    $(".cert-nav .dynamic").removeClass("act");
    $(".cert-nav .dynamic").eq(i).addClass("act");
    if (i === 0) {
      $("#cret2").css("display", "none");
      $(".cert-swiper2").css("display", "none");
      $("#cret").css("display", "block");
      $(".cert-swiper").css("display", "block");
    } else if (i === 1) {
      $("#cret").css("display", "none");
      $(".cert-swiper").css("display", "none");
      $("#cret2").css("display", "block");
      $(".cert-swiper2").css("display", "block");
      new Swiper(".cert-swiper2", {
        navigation: {
          nextEl: ".cert-next2",
          prevEl: ".cert-prev2",
        },
      });
    }
  });
});

$(function () {
  $(".scroll").scroll({
    speed: 50, //数值越大，速度越快
    direction: "horizantal",
  });
});

/* 地图 */
var myChart = echarts.init(document.getElementById("map"));
myChart.showLoading();
$.getJSON(
  "https://geo.datav.aliyun.com/areas_v2/bound/622900_full.json",
  function (geoJson) {
    echarts.registerMap("a", geoJson);
    myChart.hideLoading();
    var data = [
      {
        name: "永靖县",
        itemStyle: {
          color: "rgb(191,255,0)",
        },
      },
      {
        name: "积石山保安族东乡族撒拉族自治县",
        itemStyle: {
          color: "rgb(190,190,254)",
        },
      },
      {
        name: "临夏县",
        itemStyle: {
          color: "rgb(255,255,0)",
        },
      },
      {
        name: "东乡族自治县",
        itemStyle: {
          color: "rgb(254,190,255)",
        },
        textFixed: {
          靖远县: [300, 0],
        },
      },
      {
        name: "临夏市",
        itemStyle: {
          color: "rgb(255,123,1)",
        },
      },
      {
        name: "和政县",
        itemStyle: {
          color: "rgb(0,190,0)",
        },
      },
      {
        name: "康乐县",
        itemStyle: {
          color: "rgb(59,254,255)",
        },
      },
      {
        name: "广河县",
        itemStyle: {
          color: "rgb(255,190,0)",
        },
      },
    ];
    option = {
      backgroundColor: "#fff",
      title: {
        textStyle: {
          color: "#ccc",
        },
      },
      tooltip: {
        trigger: "item",
        backgroundColor: "#09bdb1",
        borderColor: "#FFFFCC",
        showDelay: 0,
        hideDelay: 0,
        enterable: true,
        transitionDuration: 0,
        extraCssText: "z-index:100",
        formatter: function (params, ticket, callback) {
          //根据业务自己拓展要显示的内容
          var res = "";
          var name = params.name;
          var value = params.value;
          res = "<span style='color:#fff;'>" + name + "</span>";
          return res;
        },
      },
      series: [
        {
          type: "map",
          mapType: "a",
          label: {
            show: true,
          },
          zoom: 1,
          aspectScale: 1,
          itemStyle: {
            //地图区域的多边形 图形样式
            normal: {
              //是图形在默认状态下的样式
              label: {
                show: true, //是否显示标签
                fontSize: 14,
              },
              borderWidth: 0,
            },
          },
          label: {
            normal: {
              textStyle: {
                fontSize: 14,
                lineHeight: 18,
              },
              formatter: function (val) {
                var strs = val.data.name.split(""); //字符串数组
                var str = "";
                for (var i = 0, s; (s = strs[i++]); ) {
                  //遍历字符串数组
                  str += s;
                  if (!(i % 10)) str += "\n"; // 换行
                }
                return str;
              },
            },
          },
          data: data,
        },
      ],
    };
    myChart.setOption(option);
    myChart.on("click", function (param) {
      var name = param.name;
      if (name == "永靖县") {
        window.open("");
      } else if (name == "积石山保安族东乡族撒拉族自治县") {
        window.open("");
      } else if (name == "临夏县") {
        window.open("");
      } else if (name == "东乡族自治县") {
        window.open("");
      } else if (name == "临夏市") {
        window.open("");
      } else if (name == "和政县") {
        window.open("");
      } else if (name == "康乐县") {
        window.open("");
      } else if (name == "广河县") {
        window.open("");
      }
    });
  }
);
